The Greeks are a simple shorthand way of describing the way that the value of an option (or other derivative) varies as one some other underlying variable varies
You will probably be familiar with the Greeks in the context of the Black-Scholes model but the Greeks also exist for Gram-Charlier and the Heston SV model and they are defined in exactly the same way
The Greeks can be worked out analytically through calculus (some of which becomes very complicated) or more easily they can be calculated (approximated) by the finite difference method. This method although strictly an approximation can be performed to an arbitrary degree of accuracy and so is perfectly adequate for the vast majority of purposes
The standard Greeks for the Black Scholes model are as follows:
Delta: $\Delta = \frac{\partial C}{\partial S} = \Theta(d_1)$
Theta: $\theta = \frac{\partial C}{\partial t} = - \frac{S \phi(d_1) \sigma}{2 \sqrt{T-t}}-r K e^{-r(T-t)} \Theta(d_2)$
Gamma: $\Gamma = \frac{\partial C}{\partial \Delta} = \frac{\phi(d_1)}{S \sigma \sqrt{T-t}}$
Rho: $\rho = \frac{\partial C}{\partial r} = K(T-t) e^{-r(T-t)} \Theta(d_2)$
Vega: $\nu = \frac{\partial C}{\partial \sigma} = S\phi(d_1) \sqrt{T-t}$
Formulas given are for call options
This spreadsheet allows you to experiment with the Greeks and different parameters
For an option $S_t \phi(d_1) = K e^{-r(T-t)} \phi(d_2)$
where: $d_1=\frac{ln\left(\frac{S_t}{K}\right) + \left(r+\frac{\sigma^2}{2}\right)(T-t)}{\sigma \sqrt{T-t}}$
and $d_2=d_1 - \sigma \sqrt{T-t}$
Proof
$\phi(x)=\frac{1}{\sqrt{2 \pi}} e^{\frac{-x^2}{2}}$
$\therefore \frac{\phi(d_1)}{\phi(d_2)}=e^{\frac{1}{2}\left(d_2^2-d_1^2\right)}$
$\therefore \frac{\phi(d_1)}{\phi(d_2)}=e^{\frac{1}{2}\left(d_2-d_1\right)\left(d_2+d_1\right)}$
$\therefore \frac{\phi(d_1)}{\phi(d_2)}=e^{-\frac{1}{2} \sigma \sqrt{T-t} \left(2 d_1 - \sigma \sqrt{T-t}\right)}$
$\therefore \frac{\phi(d_1)}{\phi(d_2)}=e^{-\frac{1}{2} \sigma \sqrt{T-t} \left( \frac{2 ln \frac{S_t}{K} + (2r + \sigma^2)(T-t)}{\sigma \sqrt{T-t}}-\sigma \sqrt{T-t}\right)}$
$\therefore \frac{\phi(d_1)}{\phi(d_2)}=e^{-ln \frac{S_t}{K} -\frac{1}{2} (2r+\sigma^2)(T-t) + \frac{1}{2} \sigma^2(T-t)}$
$\therefore \frac{\phi(d_1)}{\phi(d_2)}=e^{-ln \frac{S_t}{K} -r(T-t)}$
$\therefore \frac{\phi(d_1)}{\phi(d_2)}=\frac{K}{S_t} e^{-r(T-t)}$
$\therefore S_t \phi(d_1) = Ke^{-r(T-t)}\phi(d_2)$
Proof
We wish to calculate the rate of change of a call option with the underlying share price
That is we want $\frac{\partial C}{\partial S}$
where $C=S_t \Theta(d_1) - K e^{-r(T-t)} \Theta(d_2)$
$d_1=\frac{ln\left(\frac{S_t}{K}\right) + \left(r+\frac{\sigma^2}{2}\right)(T-t)}{\sigma \sqrt{T-t}}$
$d_2=d_1 - \sigma \sqrt{T-t}$
We start with a straightforward differentiation
$\Delta=\frac{\partial C_t}{S_t} = \Theta(d_1)+S_t \phi(d_1) \frac{\partial d_1}{\partial S_t} - K e ^{-r(T-t)} \phi(d_2) \frac{\partial d_2}{\partial S_t}$
$\Delta=\frac{\partial C_t}{S_t} = \Theta(d_1)+S_t \phi(d_1) \left[ \frac{\partial d_1}{\partial S_t} - \frac{\partial d_2}{\partial S_t}\right]$
$\Delta=\frac{\partial C_t}{S_t} = \Theta(d_1)+S_t \phi(d_1) \frac{\partial (d_1 - d_2)}{\partial S_t}$
$\Delta=\frac{\partial C_t}{S_t} = \Theta(d_1)$
Proof
We wish to calculate the rate of change of a the Delta of a call option with the underlying share price
That is we want $\Gamma = \frac{\partial \Delta}{\partial S_t} = \frac{\partial}{\partial S_t} \Theta(d_1)$
$\Gamma = \phi(d_1) \times \frac{\partial}{\partial S_t} \left(\frac{ln\left(\frac{S_t}{K}\right) + \left(r+\frac{\sigma^2}{2}\right)(T-t)}{\sigma \sqrt{T-t}} \right)$
$\Gamma = \phi(d_1) \times \frac{1}{S_t} \frac{1}{\sigma \sqrt{T-t}}$
$\Gamma = \frac{\phi(d_1)}{S_t \sigma \sqrt{T-t}}$
Proof
We wish to calculate the rate of change of a call option with respect to time
That is we want $\theta = \frac{\partial C_t}{\partial t}$
$\theta = S_t \phi(d_1).\frac{\partial d_1}{\partial t} - K r e^{-r(T-t)} \Theta(d_2) - K e^{-r(T-t)} \phi(d_2) \frac{\partial d_2}{\partial t}$
and
$d_1-d_2 = \sigma \sqrt{T-t}$
$\therefore \frac{\partial(d_1 - d_2)}{\partial t} = \sigma \frac{1}{2} (T-t)^{\frac{-1}{2}}.(-1)$
$\therefore \frac{\partial(d_1 - d_2)}{\partial t} = \frac{-\sigma}{2 \sqrt{T-t}}$
$\theta = S_t \phi(d_1) \left[\frac{\partial d_1}{\partial t} - \frac{\partial d_2}{\partial t} \right] - K r e^{-r(T-t)} \Theta(d_2)$
$\theta = \frac{-S_t \phi(d_1) \sigma}{2 \sqrt{T-t}} - K r e^{-r(T-t)} \Theta(d_2)$
Proof
We wish to calculate the rate of change of a call option with the volatility of the underlying share
That is we want $\frac{\partial C}{\partial \sigma}$
We start with a straightforward differentiation
$\nu=\frac{\partial C_t}{\partial \sigma} = S_t \phi(d_1) \frac{\partial d_1}{\partial \sigma} - K e^{-r(T-t)} \phi(d_2) \frac{\partial d_2}{\partial \sigma}$
and
$d_1-d_2 = \sigma \sqrt{T-t}$
$\therefore \frac{\partial(d_1 - d_2)}{\partial \sigma} = \sqrt{T-t}$
$\nu=S_t \phi(d_1) \frac{\partial(d_1 - d_2)}{\partial \sigma}$
$\nu=S_t \phi(d_1) \sqrt{T-t}$
Proof
We wish to calculate the rate of change of a call option with the risk free rate of interest
That is we want $\frac{\partial C}{\partial r}$
We start with a straightforward differentiation
$\rho=S_t \phi(d_1) \frac{\partial d_1}{\partial r} + K(T-t) e^{-r(T-t)} \Theta(d_2) - K e^{-r(T-t)} \phi(d_2) \frac{\partial d_2}{\partial r}$
$\rho=S_t \phi(d_1) \frac{\partial (d_1-d_2)}{\partial r} + K(T-t) e^{-r(T-t)} \Theta(d_2)$
$\rho=S_t \phi(d_1) \times 0 + K(T-t) e^{-r(T-t)} \Theta(d_2)$
$\rho=K(T-t) e^{-r(T-t)} \Theta(d_2)$
We do not attempt to derive the Gram-Charlier Greeks as the algebra is very complicated and does not add to any fuller understanding of the subject
The formulas for a call option are as follows:
$\Delta=\Theta(d)-\frac{\gamma_{1T}}{3!}\phi(d)(1-d^2+3d\sigma_T - 2\sigma^2_T) + \frac{\gamma_{2T}}{4!} \phi(d)[3d(1-\sigma^2_T)+4d^2\sigma_T-d^3-4\sigma_T+3\sigma_T^2]$
$\Gamma=\frac{\phi(d)}{S \sigma_T} - \frac{\gamma_{1T}}{3!} \frac{\phi(d)}{S \sigma_T} [d^3 + d(2 \sigma^2_T-3)+3\sigma_T(1-d^2)]+\frac{\gamma_{2T}}{4!} \frac{\phi(d)}{s \sigma_T} [d^4 + 3(1-d^2)(1-2 \sigma^2_T)+4 d \sigma_T(3-d^2)-3d(\sigma^2_T+d)]$
$V=S \phi(d) \sqrt{T} + \frac{\gamma_{1T}}{3!} S \phi(d) \sqrt{T} [3 \sigma \sqrt{T}(1+d^2)-d(d^2+2 \sigma^2 T)] + \frac{\gamma_{2T}}{4!} S \phi(d) \sqrt{T} [(1-d^2+3 d \sigma \sqrt{T} - 3 \sigma^2 T)(\sigma d d' - 1)+2 d d' \sigma + 3 \sigma^2 T]$
where $d=\frac{ln\left(\frac{S}{K}\right)+ rT +\frac{\sigma^2_T}{2}}{\sigma_T}$ and $d'=\sqrt{T} - \frac{d}{\sigma}$
$\rho = KTe^{-rT}\Theta(d-\sigma_T) - \frac{\gamma_{1T}}{3!} ST \phi(d)[-d^2+2d \sigma_T+1] + \frac{\gamma_{2T}}{4!} S T \phi(d)[-d^3+3(d \sigma_T+1)(d-\sigma_T)]$
$\Theta=rKe^{-rT} \Theta(d - \sigma \sqrt{T}) - S \phi(d) \frac{\sigma}{2 \sqrt{T}}-\frac{\gamma_1}{3!} S \sigma \phi(d) \left[(d-2\sigma\sqrt{T})dd' + \left(\frac{\sigma}{\sqrt{T}}-d'\right)dd'+\frac{1}{2T^{3/2}}(1-d^2)-3\sigma d' + \frac{3 \sigma^2}{2\sqrt{T}}\right]$
where $d'=\frac{r+\sigma^2/2}{\sigma\sqrt{T}} - \frac{d}{2T}$
Happily having defined a number of interim values such as $P$ and $f$ for the Heston SV model the definitions of the Greeks are 'relatively' straightforward
Using the same definitions as in the original model of the price of a call option the Greeks are as follows
$\Delta = P_1$
$\Gamma = \frac{1}{\pi S} \displaystyle\int_0^{\infty}Re\left[e^{-i \phi ln K}f_1 \right] d\phi$
$\rho = K e^{-r(T-t)}(T-t)P_2$
$V=S_t \frac{\partial P_1}{\partial \sigma} - Ke^{-r(T-t)} \frac{\partial P_2}{\partial \sigma}$
where $\frac{\partial P_j}{\partial \sigma} = \frac{1}{\pi} \displaystyle\int_0^{\infty} Re\left[\frac{e^{-i \phi ln K} f_j B_j}{i \phi} \right] d \phi$
$\Theta = -S \frac{\partial P_1}{\partial \tau} + K e^{-r \tau} \left(\frac{\partial P_2}{\partial \tau} - r P_2 \right)$
Although the above formulas and proofs are the analytically correct methods of working out the Greeks - given that in reality there are so many approximations involved in each of the models - it really makes little sense to program all these formulas in.
For practical purposes therefore, we use the finite difference method - in which we simply draw a very short chord on the graph of the option price and calculate the gradient of the chord
So for example the delta of a call option can be calculated as:
$\Delta = \frac{C_t(S_t + \delta S, K, r, \sigma, T) - C_t(S_t - \delta S, K, r, \sigma, T)}{2 \delta S}$
All the other Greeks work by analogy
The coursework calculations below all use $\delta = 1 \times 10^{-8}$